package com.example.dorm1_demo.mapper;
import com.example.dorm1_demo.entity.Dormitory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DormitoryMapper {

    //查询所有宿舍信息
    @Select("SELECT * FROM dormitory")
    List<Dormitory> selectAll();

    //插入新的宿舍信息
    @Insert("INSERT INTO dormitory(dormitoryNumber, building, floor, type, capacity, occupied, status) " +
            "VALUES(#{dormitoryNumber}, #{building}, #{floor}, #{type}, #{capacity}, #{occupied}, #{status})")
    int insert(Dormitory dormitory);

    //更新已有的宿舍信息
    @Update("UPDATE dormitory SET dormitoryNumber=#{dormitoryNumber}, building=#{building}, " +
            "floor=#{floor}, type=#{type}, capacity=#{capacity}, occupied=#{occupied}, status=#{status} WHERE id=#{id}")
    int update(Dormitory dormitory);

    //根据宿舍 ID 删除宿舍信息
    @Delete("DELETE FROM dormitory WHERE id=#{id}")
    int delete(Integer id);

    //根据宿舍 ID 查询宿舍详细信息
    @Select("SELECT * FROM dormitory WHERE id=#{id}")
    Dormitory selectById(Integer id);

    //根据宿舍号查询宿舍信息
    @Select("SELECT * FROM dormitory WHERE dormitoryNumber LIKE CONCAT('%',#{number},'%')")
    List<Dormitory> selectByNumber(String number);

    //根据宿舍楼名称查询宿舍信息
    @Select("SELECT * FROM dormitory WHERE building LIKE CONCAT('%',#{building},'%')")
    List<Dormitory> selectByBuilding(String building);
}